package com.cskaoyan.controller.lz_controller;


import com.cskaoyan.bean.GoodsExample;
import com.cskaoyan.bean.GoodsProductExample;
import com.cskaoyan.bean.OrderExample;

import com.cskaoyan.bean.UserExample;
import com.cskaoyan.bean.lzpackage.lz_count.Total;
import com.cskaoyan.bean.lzpackage.lz_count.TotalData;
import com.cskaoyan.mapper.GoodsMapper;
import com.cskaoyan.mapper.GoodsProductMapper;
import com.cskaoyan.mapper.OrderMapper;

import com.cskaoyan.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;

@RestController
@RequestMapping("admin")
public class AdminDashboardController {
    @Autowired
    UserMapper userMapper;
    @Autowired
    GoodsMapper goodsMapper;
    @Autowired
    GoodsProductMapper productMapper;
    @Autowired
    OrderMapper orderMapper;
    @RequestMapping("dashboard")
    public TotalData dashboard() throws IOException {
      Total data=new Total();
        UserExample userExample = new UserExample();
        UserExample.Criteria usercriteria = userExample.createCriteria();
        GoodsExample goodsExample = new GoodsExample();
        GoodsExample.Criteria goodscriteria = goodsExample.createCriteria();
        GoodsProductExample productExample = new GoodsProductExample();
        GoodsProductExample.Criteria productExampleCriteria = productExample.createCriteria();
        OrderExample orderExample = new OrderExample();
        OrderExample.Criteria orderExampleCriteria = orderExample.createCriteria();
        //获取goods数量
        long goodsTotal = goodsMapper.countByExample(goodsExample);
        data.setGoodsTotal(goodsTotal);
        //获取user数量
        long userTotal =  userMapper.countByExample(userExample);
        System.out.println(userTotal);
        data.setUserTotal(userTotal);
        //获取product数量
        long productTotal =  productMapper.countByExample(productExample);
        data.setProductTotal(productTotal);
        //获取order数量
        long orderTotal =  orderMapper.countByExample(orderExample);
        data.setOrderTotal(orderTotal);
        return TotalData.ok(data);
    }
}
